#include "../include/client.h"
#include "../include/clientEntrance.h"


int main(int argc,char* argv[])
{
    ARGS_CHECK(argc,3);
    int sockfd = tcp_Init(argv[1],argv[2]);
    
    /* int ret =  sign_or_land(sockfd); */
    client_entrance(sockfd);


    char line[256];

    while(1)
    {
        bzero(line,sizeof(line));
        int ret = read(STDIN_FILENO,line,sizeof(line));
        ERROR_CHECK(ret,-1,"read");
        int sret = send_cmd(line,sockfd);
        if(sret == -1)
        {
            continue;
        }
        train_t train;
        bzero(&train,sizeof(train));
        recv(sockfd,&train.type,sizeof(train.type),MSG_WAITALL);
        recv(sockfd,&train.len,sizeof(train.len),MSG_WAITALL);
        if(train.len == 0)
        {
            continue;
        }
        recv(sockfd,train.data,train.len,MSG_WAITALL);
        printf("--------------------------------------\n");
        printf("%s\n",train.data);
        printf("--------------------------------------\n");
    }
    close(sockfd);
    return 0;
}

